package c.e.b;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import android.os.UserManager;
import android.util.Base64;
import android.util.Log;
import c.e.a.b.b.h.h;
import c.e.a.b.b.j.f;
import c.e.b.g.k;
import c.e.b.g.r;
import c.e.b.g.s;
import c.e.b.g.t;
import com.huawei.hms.jos.games.ranking.RankingConst;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.concurrent.GuardedBy;

/* compiled from: FirebaseApp */
public class c {
    public static final Object i = new Object();
    public static final Executor j = new d(null);
    @GuardedBy("LOCK")
    public static final Map<String, c> k = new b.f.a();
    public final Context a;
    public final String b;
    public final e c;
    public final k d;
    public final AtomicBoolean e = new AtomicBoolean(false);
    public final AtomicBoolean f = new AtomicBoolean();
    public final t<c.e.b.n.a> g;
    public final List<b> h = new CopyOnWriteArrayList();

    /* compiled from: FirebaseApp */
    public interface b {
        void a(boolean z);
    }

    /* compiled from: FirebaseApp */
    public static class d implements Executor {
        public static final Handler a = new Handler(Looper.getMainLooper());

        public d(a aVar) {
        }

        public void execute(Runnable runnable) {
            a.post(runnable);
        }
    }

    @TargetApi(24)
    /* compiled from: FirebaseApp */
    public static class e extends BroadcastReceiver {
        public static AtomicReference<e> b = new AtomicReference();
        public final Context a;

        public e(Context context) {
            this.a = context;
        }

        public void onReceive(Context context, Intent intent) {
            Object obj = c.i;
            synchronized (c.i) {
                for (c d : c.k.values()) {
                    d.d();
                }
            }
            this.a.unregisterReceiver(this);
        }
    }

    @TargetApi(14)
    /* compiled from: FirebaseApp */
    public static class c implements c.e.a.b.b.g.a.a.a {
        public static AtomicReference<c> a = new AtomicReference();

        public void a(boolean z) {
            Object obj = c.i;
            synchronized (c.i) {
                Iterator it = new ArrayList(c.k.values()).iterator();
                while (it.hasNext()) {
                    c cVar = (c) it.next();
                    if (cVar.e.get()) {
                        Log.d("FirebaseApp", "Notifying background state change listeners.");
                        for (b a : cVar.h) {
                            a.a(z);
                        }
                    }
                }
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:15:0x0079  */
    /* JADX WARNING: Removed duplicated region for block: B:14:0x006f  */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x00c4  */
    /* JADX WARNING: Removed duplicated region for block: B:46:0x017e  */
    public c(android.content.Context r13, java.lang.String r14, c.e.b.e r15) {
        /*
        r12 = this;
        r12.<init>();
        r0 = new java.util.concurrent.atomic.AtomicBoolean;
        r1 = 0;
        r0.<init>(r1);
        r12.e = r0;
        r0 = new java.util.concurrent.atomic.AtomicBoolean;
        r0.<init>();
        r12.f = r0;
        r0 = new java.util.concurrent.CopyOnWriteArrayList;
        r0.<init>();
        r12.h = r0;
        r0 = new java.util.concurrent.CopyOnWriteArrayList;
        r0.<init>();
        r0 = "null reference";
        java.util.Objects.requireNonNull(r13, r0);
        r12.a = r13;
        b.i.b.f.N(r14);
        r12.b = r14;
        java.util.Objects.requireNonNull(r15, r0);
        r12.c = r15;
        r14 = com.google.firebase.components.ComponentDiscoveryService.class;
        r0 = "ComponentDiscovery";
        r2 = 0;
        r3 = r13.getPackageManager();	 Catch:{ NameNotFoundException -> 0x0065 }
        if (r3 != 0) goto L_0x0040;
    L_0x003a:
        r14 = "Context has no PackageManager.";
        android.util.Log.w(r0, r14);	 Catch:{ NameNotFoundException -> 0x0065 }
        goto L_0x006a;
    L_0x0040:
        r4 = new android.content.ComponentName;	 Catch:{ NameNotFoundException -> 0x0065 }
        r4.<init>(r13, r14);	 Catch:{ NameNotFoundException -> 0x0065 }
        r5 = 128; // 0x80 float:1.794E-43 double:6.32E-322;
        r3 = r3.getServiceInfo(r4, r5);	 Catch:{ NameNotFoundException -> 0x0065 }
        if (r3 != 0) goto L_0x0062;
    L_0x004d:
        r3 = new java.lang.StringBuilder;	 Catch:{ NameNotFoundException -> 0x0065 }
        r3.<init>();	 Catch:{ NameNotFoundException -> 0x0065 }
        r3.append(r14);	 Catch:{ NameNotFoundException -> 0x0065 }
        r14 = " has no service info.";
        r3.append(r14);	 Catch:{ NameNotFoundException -> 0x0065 }
        r14 = r3.toString();	 Catch:{ NameNotFoundException -> 0x0065 }
        android.util.Log.w(r0, r14);	 Catch:{ NameNotFoundException -> 0x0065 }
        goto L_0x006a;
    L_0x0062:
        r14 = r3.metaData;	 Catch:{ NameNotFoundException -> 0x0065 }
        goto L_0x006b;
    L_0x0065:
        r14 = "Application info not found.";
        android.util.Log.w(r0, r14);
    L_0x006a:
        r14 = r2;
    L_0x006b:
        r3 = "com.google.firebase.components.ComponentRegistrar";
        if (r14 != 0) goto L_0x0079;
    L_0x006f:
        r14 = "Could not retrieve metadata, returning empty list of registrars.";
        android.util.Log.w(r0, r14);
        r14 = java.util.Collections.emptyList();
        goto L_0x00af;
    L_0x0079:
        r4 = new java.util.ArrayList;
        r4.<init>();
        r5 = r14.keySet();
        r5 = r5.iterator();
    L_0x0086:
        r6 = r5.hasNext();
        if (r6 == 0) goto L_0x00ae;
    L_0x008c:
        r6 = r5.next();
        r6 = (java.lang.String) r6;
        r7 = r14.get(r6);
        r7 = r3.equals(r7);
        if (r7 == 0) goto L_0x0086;
    L_0x009c:
        r7 = "com.google.firebase.components:";
        r7 = r6.startsWith(r7);
        if (r7 == 0) goto L_0x0086;
    L_0x00a4:
        r7 = 31;
        r6 = r6.substring(r7);
        r4.add(r6);
        goto L_0x0086;
    L_0x00ae:
        r14 = r4;
    L_0x00af:
        r4 = "Could not instantiate %s";
        r5 = "Could not instantiate %s.";
        r6 = new java.util.ArrayList;
        r6.<init>();
        r14 = r14.iterator();
    L_0x00bc:
        r7 = r14.hasNext();
        r8 = 2;
        r9 = 1;
        if (r7 == 0) goto L_0x013b;
    L_0x00c4:
        r7 = r14.next();
        r7 = (java.lang.String) r7;
        r10 = java.lang.Class.forName(r7);	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r11 = c.e.b.g.g.class;
        r11 = r11.isAssignableFrom(r10);	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        if (r11 != 0) goto L_0x00e6;
    L_0x00d6:
        r10 = "Class %s is not an instance of %s";
        r8 = new java.lang.Object[r8];	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r8[r1] = r7;	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r8[r9] = r3;	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r8 = java.lang.String.format(r10, r8);	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        android.util.Log.w(r0, r8);	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        goto L_0x00bc;
    L_0x00e6:
        r8 = new java.lang.Class[r1];	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r8 = r10.getDeclaredConstructor(r8);	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r10 = new java.lang.Object[r1];	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r8 = r8.newInstance(r10);	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r8 = (c.e.b.g.g) r8;	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        r6.add(r8);	 Catch:{ ClassNotFoundException -> 0x012c, IllegalAccessException -> 0x011f, InstantiationException -> 0x0112, NoSuchMethodException -> 0x0105, InvocationTargetException -> 0x00f8 }
        goto L_0x00bc;
    L_0x00f8:
        r8 = move-exception;
        r9 = new java.lang.Object[r9];
        r9[r1] = r7;
        r7 = java.lang.String.format(r4, r9);
        android.util.Log.w(r0, r7, r8);
        goto L_0x00bc;
    L_0x0105:
        r8 = move-exception;
        r9 = new java.lang.Object[r9];
        r9[r1] = r7;
        r7 = java.lang.String.format(r4, r9);
        android.util.Log.w(r0, r7, r8);
        goto L_0x00bc;
    L_0x0112:
        r8 = move-exception;
        r9 = new java.lang.Object[r9];
        r9[r1] = r7;
        r7 = java.lang.String.format(r5, r9);
        android.util.Log.w(r0, r7, r8);
        goto L_0x00bc;
    L_0x011f:
        r8 = move-exception;
        r9 = new java.lang.Object[r9];
        r9[r1] = r7;
        r7 = java.lang.String.format(r5, r9);
        android.util.Log.w(r0, r7, r8);
        goto L_0x00bc;
    L_0x012c:
        r8 = move-exception;
        r9 = new java.lang.Object[r9];
        r9[r1] = r7;
        r7 = "Class %s is not an found.";
        r7 = java.lang.String.format(r7, r9);
        android.util.Log.w(r0, r7, r8);
        goto L_0x00bc;
    L_0x013b:
        r14 = c.e.a.c.a.e();
        r0 = new c.e.b.g.k;
        r3 = j;
        r4 = 8;
        r4 = new c.e.b.g.d[r4];
        r5 = android.content.Context.class;
        r7 = new java.lang.Class[r1];
        r5 = c.e.b.g.d.c(r13, r5, r7);
        r4[r1] = r5;
        r5 = c.e.b.c.class;
        r7 = new java.lang.Class[r1];
        r5 = c.e.b.g.d.c(r12, r5, r7);
        r4[r9] = r5;
        r5 = c.e.b.e.class;
        r7 = new java.lang.Class[r1];
        r15 = c.e.b.g.d.c(r15, r5, r7);
        r4[r8] = r15;
        r15 = 3;
        r5 = "fire-android";
        r7 = "";
        r5 = c.e.a.c.a.b(r5, r7);
        r4[r15] = r5;
        r15 = 4;
        r5 = "fire-core";
        r7 = "19.3.1";
        r5 = c.e.a.c.a.b(r5, r7);
        r4[r15] = r5;
        r15 = 5;
        if (r14 == 0) goto L_0x0184;
    L_0x017e:
        r2 = "kotlin";
        r2 = c.e.a.c.a.b(r2, r14);
    L_0x0184:
        r4[r15] = r2;
        r14 = 6;
        r15 = c.e.b.o.f.class;
        r15 = c.e.b.g.d.a(r15);
        r2 = c.e.b.o.e.class;
        r5 = new c.e.b.g.o;
        r5.m1690init(r2, r8, r1);
        r15.a(r5);
        r2 = c.e.b.o.b.a;
        r15.d(r2);
        r15 = r15.b();
        r4[r14] = r15;
        r14 = 7;
        r15 = c.e.b.k.c.class;
        r15 = c.e.b.g.d.a(r15);
        r2 = android.content.Context.class;
        r5 = new c.e.b.g.o;
        r5.m1690init(r2, r9, r1);
        r15.a(r5);
        r1 = c.e.b.k.a.a;
        r15.d(r1);
        r15 = r15.b();
        r4[r14] = r15;
        r0.m8007init(r3, r6, r4);
        r12.d = r0;
        r14 = new c.e.b.g.t;
        r15 = new c.e.b.b;
        r15.m6038init(r12, r13);
        r14.m6058init(r15);
        r12.g = r14;
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.b.c.m1677init(android.content.Context, java.lang.String, c.e.b.e):void");
    }

    public static c b() {
        c cVar;
        synchronized (i) {
            cVar = (c) k.get("[DEFAULT]");
            if (cVar != null) {
            } else {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Default FirebaseApp is not initialized in this process ");
                stringBuilder.append(f.a());
                stringBuilder.append(". Make sure to call FirebaseApp.initializeApp(Context) first.");
                throw new IllegalStateException(stringBuilder.toString());
            }
        }
        return cVar;
    }

    public static c e(Context context, e eVar) {
        Object context2;
        c cVar;
        AtomicReference atomicReference = c.a;
        boolean z = true;
        if (context2.getApplicationContext() instanceof Application) {
            Application application = (Application) context2.getApplicationContext();
            if (c.a.get() == null) {
                c cVar2 = new c();
                if (c.a.compareAndSet(null, cVar2)) {
                    c.e.a.b.b.g.a.a aVar = c.e.a.b.b.g.a.a.e;
                    synchronized (aVar) {
                        if (!aVar.d) {
                            application.registerActivityLifecycleCallbacks(aVar);
                            application.registerComponentCallbacks(aVar);
                            aVar.d = true;
                        }
                    }
                    synchronized (aVar) {
                        aVar.c.add(cVar2);
                    }
                }
            }
        }
        String str = "[DEFAULT]";
        if (context2.getApplicationContext() != null) {
            context2 = context2.getApplicationContext();
        }
        synchronized (i) {
            Map map = k;
            if (map.containsKey(str)) {
                z = false;
            }
            b.i.b.f.U(z, "FirebaseApp name [DEFAULT] already exists!");
            b.i.b.f.S(context2, "Application context cannot be null.");
            cVar = new c(context2, str, eVar);
            map.put(str, cVar);
        }
        cVar.d();
        return cVar;
    }

    public final void a() {
        b.i.b.f.U(this.f.get() ^ 1, "FirebaseApp was deleted");
    }

    public String c() {
        String str;
        StringBuilder stringBuilder = new StringBuilder();
        a();
        byte[] bytes = this.b.getBytes(Charset.defaultCharset());
        String str2 = null;
        if (bytes == null) {
            str = null;
        } else {
            str = Base64.encodeToString(bytes, 11);
        }
        stringBuilder.append(str);
        stringBuilder.append("+");
        a();
        bytes = this.c.b.getBytes(Charset.defaultCharset());
        if (bytes != null) {
            str2 = Base64.encodeToString(bytes, 11);
        }
        stringBuilder.append(str2);
        return stringBuilder.toString();
    }

    public final void d() {
        StringBuilder stringBuilder;
        if (((VERSION.SDK_INT >= 24 ? ((UserManager) this.a.getSystemService(UserManager.class)).isUserUnlocked() : 1) ^ 1) != 0) {
            stringBuilder = new StringBuilder();
            stringBuilder.append("Device in Direct Boot Mode: postponing initialization of Firebase APIs for app ");
            a();
            stringBuilder.append(this.b);
            Log.i("FirebaseApp", stringBuilder.toString());
            Context context = this.a;
            if (e.b.get() == null) {
                e eVar = new e(context);
                if (e.b.compareAndSet(null, eVar)) {
                    context.registerReceiver(eVar, new IntentFilter("android.intent.action.USER_UNLOCKED"));
                    return;
                }
                return;
            }
            return;
        }
        stringBuilder = new StringBuilder();
        stringBuilder.append("Device unlocked: initializing all Firebase APIs for app ");
        a();
        stringBuilder.append(this.b);
        Log.i("FirebaseApp", stringBuilder.toString());
        k kVar = this.d;
        boolean g = g();
        for (Entry entry : kVar.a.entrySet()) {
            c.e.b.g.d dVar = (c.e.b.g.d) entry.getKey();
            t tVar = (t) entry.getValue();
            int i = dVar.c;
            Object obj = null;
            if ((i == 1 ? 1 : null) == null) {
                if (i == 2) {
                    obj = 1;
                }
                if (obj != null) {
                    if (!g) {
                    }
                }
            }
            tVar.get();
        }
        s sVar = kVar.d;
        synchronized (sVar) {
            Queue queue = sVar.b;
            if (queue != null) {
                sVar.b = null;
            } else {
                queue = null;
            }
        }
        if (queue != null) {
            for (c.e.b.j.a aVar : queue) {
                Objects.requireNonNull(aVar);
                synchronized (sVar) {
                    Queue queue2 = sVar.b;
                    if (queue2 != null) {
                        queue2.add(aVar);
                    } else {
                        synchronized (sVar) {
                            Map map = (Map) sVar.a.get(null);
                            Set<Entry> emptySet = map == null ? Collections.emptySet() : map.entrySet();
                        }
                        for (Entry entry2 : emptySet) {
                            ((Executor) entry2.getValue()).execute(new r(entry2, aVar));
                        }
                    }
                }
            }
        }
    }

    public boolean equals(Object obj) {
        if (!(obj instanceof c)) {
            return false;
        }
        String str = this.b;
        c cVar = (c) obj;
        cVar.a();
        return str.equals(cVar.b);
    }

    public boolean f() {
        boolean z;
        a();
        c.e.b.n.a aVar = (c.e.b.n.a) this.g.get();
        synchronized (aVar) {
            z = aVar.d;
        }
        return z;
    }

    public boolean g() {
        a();
        return "[DEFAULT]".equals(this.b);
    }

    public int hashCode() {
        return this.b.hashCode();
    }

    public String toString() {
        h hVar = new h(this, null);
        hVar.a(RankingConst.RANKING_JGW_NAME, this.b);
        hVar.a("options", this.c);
        return hVar.toString();
    }
}
